package br.com.erpcortume.interceptors;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class AuthenticationInterceptor extends HandlerInterceptorAdapter {
	
	@Override
	public boolean preHandle(HttpServletRequest req,
			HttpServletResponse resp, Object handler) throws Exception {
		
		String uri = req.getRequestURI();
		if (uri.endsWith("login") || uri.endsWith("logar")
				|| uri.contains("resources")) {
			
			return true;
		}
		
		if(req.getSession().getAttribute("userSession") != null) {
	        return true;
	      }
		
		resp.sendRedirect("logar");
		return false;
	}

}
